package com.xykj.mythy.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@Component
public class ScheduledService {

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Async
    @Scheduled(cron = "0/5 * * * * *")
    public void scheduled(){
        log.info("<<cron>>  {}",sdf.format(new Date()));
    }

    @Async
    @Scheduled(fixedRate = 5000)
    public void scheduled1() {
       log.info("<<fixedRate>>  {}", sdf.format(new Date()));
    }

    @Async
    @Scheduled(fixedDelay = 5000)
    public void scheduled2() {
       log.info("<<fixedDelay>>  {}",sdf.format(new Date()));
    }

}